package com.wuyou.gen;


//import com.baomidou.mybatisplus.generator.FastAutoGenerator;
//import com.baomidou.mybatisplus.generator.config.OutputFile;
//import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
//import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder;
import com.baomidou.mybatisplus.generator.config.po.TableFill;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.sql.Types;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

//@RunWith(SpringRunner.class)
//@SpringBootTest
//@Slf4j
class GenTest {

//    @Test
    void contextLoads() {

        System.out.println(System.getProperty("user.dir"));
        System.out.println("1731493064251080704".length());
    }


//    private static final String URL = "jdbc:mysql://58.246.191.134:30222/cy_business?serverTimezone=GMT%2B8";
    private static final String URL = "jdbc:mysql://192.168.1.1/cy_ims_dev?serverTimezone=GMT%2B8";
    private static final String USERNAME = "cy_dev";
    private static final String PASSWORD = "Cy@dev123";

//    private static final String GEN_PATH = "System.getProperty(\"user.dir\")"; // D:\git\zmh-customs-clearance-interface\zmh-customs-web

    private static final String PACKAGE_NAEM = "com.zmh";

    private static final String PARENT_MOUDLE_NAME = "";

    private static final String MAPPER_PATH = "\\mapper";


    public static void main(String[] args) {
        String moduleName = "fourport.cy.ims"; // 修改为你的模块名
//        String[] tableName = {"enterprise", "enterprise_contact", "fee", "inspect_order", "inspect_order_cost", "inspect_order_cost_files", "inspect_order_ext", "inspect_order_files", "inspect_order_msg", "inspect_order_status", "staff"}; // 生成指定;   // 修改为你的表名
        String[] tableName = {"inspect_order","inspect_reserve"}; // 生成指定;   // 修改为你的表名
        AutoGenerator generator = new AutoGenerator();

        // 全局配置
        GlobalConfig globalConfig = new GlobalConfig();
        globalConfig
                .setOutputDir(System.getProperty("user.dir") + "/src/main/java")
                .setAuthor("张宇航")
                .setOpen(false)
                .setSwagger2(true)
                .setServiceImplName("%sServiceImpl")
                .setMapperName("%sMapper")
                .setXmlName("%sMapper");
        globalConfig.setFileOverride(true);

        // 数据源配置
        DataSourceConfig dataSourceConfig = new DataSourceConfig();
        dataSourceConfig.setDbType(DbType.MYSQL)
                .setDriverName("com.mysql.cj.jdbc.Driver")
                .setUrl(URL)
                .setUsername(USERNAME)
                .setPassword(PASSWORD);

        // 包配置
        PackageConfig packageConfig = new PackageConfig();
        packageConfig.setParent(moduleName)
                .setEntity("entity")
                .setMapper("mapper")
                .setService("service")
                .setServiceImpl("service.impl")
                .setController("controller");

        // 策略配置
        StrategyConfig strategyConfig = new StrategyConfig();
        strategyConfig.setNaming(NamingStrategy.underline_to_camel)
                .setColumnNaming(NamingStrategy.underline_to_camel)
                .setEntityLombokModel(true)
                .setRestControllerStyle(true)
                .setInclude(tableName)
                .setControllerMappingHyphenStyle(true)
                .setEntityLombokModel(true);
//                .setTablePrefix(""); // 根据你的表前缀修改

        // 自定义模板配置
        TemplateConfig templateConfig = new TemplateConfig();
        templateConfig
//                .setEntity("templates/entity.java.ftl")
                .setController("templates/controller.java")
                .setService("templates/service.java")
                .setServiceImpl("templates/serviceImpl.java")
                .setMapper("templates/mapper.java")
                .setXml("templates/mapper.xml");

        // 设置模板引擎
        FreemarkerTemplateEngine templateEngine = new FreemarkerTemplateEngine();
//        ConfigBuilder configBuilder = new ConfigBuilder(packageConfig, dataSourceConfig, strategyConfig, templateConfig, globalConfig);


        generator.setDataSource(dataSourceConfig);
        generator.setGlobalConfig(globalConfig);
        generator.setPackageInfo(packageConfig);
        generator.setStrategy(strategyConfig);
        generator.setTemplate(templateConfig);
        generator.setTemplateEngine(templateEngine);

        generator.execute();
    }
}
